package com.lunhui.service.provider.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.lunhui.map.client.dto.MapInfoDto;
import com.lunhui.service.lunhui.service.business.MapService;
import com.lunhui.service.lunhui.service.business.MonsterService;
import com.lunhui.service.provider.common.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author renminghe-kg
 */
@RestController
@Api(value = "地图接口")
@RequestMapping("map")
public class LunHuiServiceMapController {
    private static final Logger logger = LoggerFactory.getLogger(LunHuiServiceMapController.class);

    @Autowired
    @Qualifier("mapService")
    private MapService mapService;

    @Autowired
    @Qualifier("monsterService")
    private MonsterService monsterService;

    @ApiOperation(value = "获取当前场景附近区域信息",httpMethod = "GET")
    @RequestMapping(value = "sceneMapInfo", method = RequestMethod.GET)
    public Result<PageInfo<MapInfoDto>> getMapInfo(@ApiParam("区域ID") Integer areaId, @ApiParam("场景ID") Integer sceneId) {
        if (areaId == null) {
            return Result.fail("区域ID无效");
        }

        try {
            PageInfo<MapInfoDto> mapInfo = mapService.getMapInfo(areaId, sceneId);
            logger.info("getMapInfo接口返回数据: " + JSONObject.toJSONString(mapInfo));
            return Result.ok(mapInfo);
        } catch (Exception e) {
            logger.error("获取地图接口数据失败：" + e);
            return Result.fail("获取地图接口数据失败");
        }

    }

    @ApiOperation(value = "获取当前场景附近怪物信息",httpMethod = "GET")
    @RequestMapping(value = "monsterMapInfo", method = RequestMethod.GET)
    public Result<String> getMonsterMapInfo(@ApiParam("区域ID") Integer areaId, @ApiParam("场景ID") Integer sceneId) {
        if (areaId == null) {
            return Result.fail("区域ID无效");
        }

        try {
            String monsterListInfo = JSONObject.toJSONString(monsterService.getMonsterListInfo(areaId, sceneId));
            logger.info("getMonsterMapInfo接口返回数据: " + JSONObject.toJSONString(monsterListInfo));
            return Result.ok(monsterListInfo);
        } catch (Exception e) {
            logger.error("获取当前场景附近怪物信息接口数据失败：" + e);
            return Result.fail("获取当前场景附近怪物信息接口数据失败");
        }

    }
}